package com.example.administrator.waitan.homepage;

import android.content.Context;
import android.graphics.Bitmap;
import android.util.Log;
import android.support.v4.util.LruCache;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.ImageLoader;
import com.android.volley.toolbox.NetworkImageView;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;
import com.example.administrator.waitan.R;
import com.example.administrator.waitan.mygreendao.HomeData;
import com.example.administrator.waitan.tools.VolleySingleton;
import com.google.gson.Gson;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/1/11.
 */
public class HomePagerBaseAdapter extends BaseAdapter {
    private Context context;
    private List<HomeData> datas;
    public HomePagerBaseAdapter(Context context) {
        this.context = context;
    }
    public void addData(List<HomeData> datas){
        this.datas = datas;
        notifyDataSetChanged();
    }
    @Override
    public int getCount() {
        return datas==null?0:datas.size();
    }

    @Override
    public Object getItem(int i) {
        return datas.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        MyViewHolder myViewHolder;
        if (view == null){
            view = LayoutInflater.from(context).inflate(R.layout.item_lv_homepager,null);
            myViewHolder = new MyViewHolder();
            myViewHolder.title = (TextView) view.findViewById(R.id.tv_item_homePager_title);
            myViewHolder.review = (TextView) view.findViewById(R.id.tv_item_homePager_content);
            myViewHolder.middleCover = (ImageView) view.findViewById(R.id.iv_item_homePager_pic);
            view.setTag(myViewHolder);
        }
        else{
            myViewHolder = (MyViewHolder) view.getTag();
        }
        myViewHolder.title.setText(datas.get(i).getTitle());
        myViewHolder.review.setText(datas.get(i).getReview());
        VolleySingleton.getImageLoader().get(datas.get(i).getBigCover(),VolleySingleton.getImageListener(myViewHolder.middleCover));
        return view;
    }

    private class MyViewHolder{
        TextView title,review;
        ImageView middleCover;
    }
}
